package com.example.back.mapper;

import com.example.back.model.Room;
import com.example.back.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoomMapper {
    @Select("select * from room")
    List<Room> findAllRoom();
    @Select("select * from room where concat(name, cost, type) like concat('%', #{information}, '%')")
    List<Room> findByInformation(String information);
    @Select("select * from room where type=#{type}")
    List<Room> roomType(String type);
    @Select("select * from room where state=#{state}")
    List<Room> roomState(int state);
    @Select("select name from room where id=#{id}")
    String findRoomName(int id);
    @Select("select account from into_room where id=#{id}")
    String findAccount(int id);
    @Select("select * from into_room left join user on user.account = into_room.account  where into_room.name=#{name} and into_room.flag!=0")
    List<User> findRoomUser(String name);
    @Select("select * from room where maxCount-count>=#{roomC}")
    List<Room> roomCount(int roomC);
    @Select("select count from room where name=#{name}")
    int findRoomCount(String name);
    @Insert("insert into room(name, cost, type, count, maxCount, state) values(#{name}, #{cost}, #{type}, 0, #{maxCount}, 0)")
    Boolean insertRoom(String name, double cost, String type, int maxCount);
    @Update("update room set cost=#{cost} where id=#{id}")
    Boolean updateRoom(int id, double cost);
    @Update("update room set remark=null, state=1 where name=#{name}")
    Boolean updateRoomRemark(String name);
    @Delete("delete from room where id=#{id}")
    Boolean deleteRoom(int id);
    @Select("select * from room left join into_room on room.name = into_room.name where into_room.flag!=0 and into_room.account=#{account}")
    Room findAtRoom(String account);
    @Update("update room set count=count+1, remark=#{remark}, state=#{state} where name=#{name}")
    Boolean createRoom(String name, int state, String remark);
    @Update("update room set count=count+1 where name=#{name}")
    Boolean joinRoom(String name);
    @Update("update room set count=count-1 where name=#{name}")
    Boolean leaveRoom(String name);
    @Insert("insert into into_room(account, name, enterTime, flag) values(#{account}, #{name}, #{enterTime}, 1)")
    Boolean intoRoom(String account, String name, String enterTime);
    @Update("update into_room set leaveTime=#{leaveTime}, flag=0 where account=#{account} and name=#{name}")
    Boolean outRoom(String account, String name, String leaveTime);
}
